/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   01.03.2010
 * @version SVN: $Id: ProductRepositoryImpl.java 97 2010-04-28 10:41:34Z christian-kerl@web.de $
 */

package org.cakis.server.model.repository.impl;

import javax.ejb.Stateless;
import javax.persistence.Query;

import org.cakis.server.Names;
import org.cakis.server.model.Product;
import org.cakis.server.model.repository.ProductRepository;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

/**
 * Implementation of the {@link ProductRepository} interface.
 * 
 * @author Christian Kerl
 */
@Name(Names.ProductRepository)
@AutoCreate
@Stateless(name=Names.ProductRepository)
public class ProductRepositoryImpl extends AbstractRepository<Product> implements ProductRepository {
    private static final long serialVersionUID = 1L;

    @Override
    protected Long getId(Product object) {
        return object.getId();
    }

    @Override
    public Product findByEanNumber(String ean) {
        Query q = em.createQuery("select p from Product p where p.eanNumber = :ean");
        q.setParameter("ean", ean);

        return one(q);
    }
}
